<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Restful web service</title>
</head>

<body>
<?php 
    if(!isset($_POST['submit']))
    {
?>
  <h1>Tesseract</h1>
 
	<form id="ocr" action="<?php echo  $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
 
	   <p>
		Select a image : <input type="file" name="file" id="file" size="45" />
	   </p>
	   
	   <p>
		Language : 
			<select name="lang" id = "lang">
  				<option value="eng">English</option>
  				<option value="vie">Vietnam</option>
			</select>
	   </p>
	   
	   
	   <input type="submit" name = "submit" value="Upload It" />
	</form>
  
<?php 	  
   }
   else 
   {
   	
   $result = "";
   	
   if ($_FILES["file"]["error"] > 0)
  	{
  		$result = "Error: " . $_FILES["file"]["error"] . "<br />";
  	}
  	else
  	{
  
    	include 'rest_client.php';
    	$path_temp = $_FILES["file"]["tmp_name"];
    	$lang = $_POST['lang'];
    	
    	$arr=array('lang'=>$lang,'image'=>"@$path_temp");
    	$url = "http://192.168.1.5:8080/TesseractAPI/tesseract";
    	$resp = RestClient::post($url,$arr);
  		$body = $resp->getResponse();
		
		$bodyDecode = json_decode($body,true);
		
		if(is_array($bodyDecode)) {
		    if($bodyDecode['error'])
				$result = "Error : ".$bodyDecode['message'];
			else
				$result = $bodyDecode['message'];
		} 
		else
			$result = $body;
		
    } 
?>
	<form action="">
    <textarea rows="25" cols="120" id="result"><?php echo $result;?></textarea>
    </form>
<?php
   } 
?>
</body>
</html>

